<template>
	<!-- 商品管理 -->
	<div class="page">
		<el-breadcrumb class="breadcrumb" separator-class="el-icon-arrow-right">
			<el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
			<el-breadcrumb-item>分类列表</el-breadcrumb-item>
		</el-breadcrumb>
		<el-table class="table" :data="goodsArr" border style="width: 100%">
			<el-table-column prop="id" label="编号">
			</el-table-column>
			<el-table-column prop="categoryName" label="分类名称">
			</el-table-column>
			<el-table-column label="操作" width="100">
				<template slot-scope="scope">
					<el-button size="small" @click.native="detail(scope.row.id)" type="success">详情</el-button>
				</template>
			</el-table-column>
		</el-table>
		<el-pagination class="page-num" background layout="prev, pager, next" :page-size="page_size" @current-change="handleCurrentChange" :total="page">
		</el-pagination>
	</div>
</template>
<script>
	export default {
		name: "manage",
		data() {
			return {
				goodsArr: [],
				params: {
					"numPerPage": 10,
					"order": "asc",
					"pageNum": 1,
					"state": "OPEN",
					"sort": ""
				},
				page_size: 2, //每页显示几个
				page: 0, //总页数
				currentPage: 1, //当前页
			};
		},
		created() {

		},
		mounted() {
			this.getList();
		},

		methods: {
			/*分页跳转*/
			handleCurrentChange: function(currentPage) {
				this.currentPage = currentPage;
				this.getList();
			},
			// 获取列表
			getList() {
				this.params.pageNum = this.currentPage;
				this.$post("categoryList", this.params).then(res => {
					if(res.code == 200) {
						this.goodsArr = [];
						this.page = res.data.total;
						var list = res.data.rows;
						for(var i in list) {
							this.goodsArr.push(list[i]);
						}
					} else {
						this.$msg.warning(res.message);
					}
				});
			},
			// 跳转详情页面
			detail(id) {
				this.$router.push({
					name: 'updateClassify',
					params: {
						id: id
					}
				})
			},
		}
	};
</script>
<style lang="less" scoped>
	.page {
		width: 100%;
		height: 100%;
		position: relative;
	}
</style>